
on boot

# for bluetooth
    # change back to bluetooth from system
    chown bluetooth net_bt_stack /data/misc/bluetooth
    mkdir /data/misc/bluedroid 0770 bluetooth net_bt_stack
    # bluetooth LPM
    chown bluetooth net_bt_stack /proc/bluetooth/sleep/lpm
    chown bluetooth net_bt_stack /proc/bluetooth/sleep/btwrite    

#   insmod /system/lib/modules/rtk_btusb.ko
    chmod 0660 /dev/rtk_btusb
    chown bluetooth net_bt_stack /dev/rtk_btusb

    # bluetooth MAC address programming
    chown bluetooth net_bt_stack ro.bt.bdaddr_path
    chown bluetooth net_bt_stack /system/etc/bluetooth
    chown bluetooth net_bt_stack /data/misc/bluetooth
    setprop ro.bt.bdaddr_path "/data/misc/bluetooth/bdaddr"

# for aic bt usb
    chmod 0660 /dev/aicbt_dev
    chown bluetooth net_bt_stack /dev/aicbt_dev

    chmod 0660 /dev/ttyS0
    chmod 0660 /dev/ttyS1
    chmod 0660 /dev/vflash
    chmod 0664 /dev/vendor_storage
    chown bluetooth net_bt_stack /dev/vflash
    chown bluetooth net_bt_stack /dev/vendor_storage
    chown bluetooth net_bt_stack /dev/ttyS1
    chown bluetooth net_bt_stack /dev/ttyS0
    chown bluetooth net_bt_stack /sys/class/rfkill/rfkill0/type
    chown bluetooth net_bt_stack /sys/class/rfkill/rfkill0/state
    chmod 0664 /sys/class/rfkill/rfkill0/state

# for wifi
#   mt7601u
#   chmod 0644 /system/lib/modules/mtprealloc7601Usta.ko

    mkdir /data/misc/wifi 0770 wifi wifi
    mkdir /data/misc/wifi/sockets 0770 wifi wifi
    mkdir /data/misc/wifi/sockets/tmp 0440 wifi wifi
    mkdir /data/misc/dhcp 0770 dhcp dhcp
    chown dhcp dhcp /data/misc/dhcp
    
    mkdir /data/misc/wifi 0770 wifi wifi
    chmod 0660 /data/misc/wifi/wpa_supplicant.conf
    chmod 0660 /data/misc/wifi/p2p_supplicant.conf
    mkdir /data/misc/wifi 0770 wifi wifi
    mkdir /data/misc/wifi/sockets 0770 wifi wifi
    chmod 777 /data/misc/wifi/sockets
    mkdir /data/misc/wpa_supplicant 0770 wifi wifi
    chown wifi wifi /data/misc/wifi 
    chown system wifi /data/misc/wifi/entropy.bin
    chown wifi wifi /data/misc/wifi/p2p_supplicant.conf
    chown wifi wifi /data/misc/wifi/wpa_supplicant.conf

#for nfc
    chmod 0660 /dev/bcm2079x
    chown nfc nfc /dev/bcm2079x
    mkdir /data/nfc
    mkdir /data/nfc/param
    chmod 0700 /data/nfc
    chmod 0700 /data/nfc/param
    chown nfc nfc /data/nfc
    chown nfc nfc /data/nfc/param

# for bcm wifi
########## 3.0.x <= kernel version <= 3.4.x ##########
service wpa_supplicant1 /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/wpa_supplicant_overlay.conf \
    -O/data/misc/wifi/sockets \
    -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0
    #      we will start as root and wpa_supplicant will switch to user wifi
    #      after setting up the capabilities required for WEXT
    #      user wifi
    #      group wifi inet keystore
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

service p2p_supplicant1 /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/wpa_supplicant_overlay.conf -N \
    -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
    -I/system/etc/wifi/p2p_supplicant_overlay.conf \
    -O/data/misc/wifi/sockets -puse_p2p_group_interface=1 \
    -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0
#      we will start as root and wpa_supplicant will switch to user wifi
#      after setting up the capabilities required for WEXT
#      user wifi
#      group wifi inet keystore
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot
########## 3.0.x <= kernel version <= 3.4.x ##########

########## kernel version >= 3.10.x ##########
service wpa_supplicant /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/wpa_supplicant_overlay.conf \
    -e/data/misc/wifi/entropy.bin -O/data/misc/wifi/sockets \
    -g@android:wpa_wlan0
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

service p2p_supplicant /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/p2p_supplicant_overlay.conf \
    -puse_p2p_group_interface=1p2p_device=1 \
    -m/data/misc/wifi/p2p_supplicant.conf \
    -e/data/misc/wifi/entropy.bin -O/data/misc/wifi/sockets \
    -g@android:wpa_wlan0
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot
########## kernel version >= 3.10.x ##########
	
# for rtl wifi
service p2p_supp_rtl /system/bin/wpa_supplicant \
    -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
    -e/data/misc/wifi/entropy.bin -N \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -O/data/misc/wifi/sockets \
    -g@android:wpa_wlan0
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

# for esp wifi
service p2p_supp_esp /system/bin/wpa_supplicant \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -I/system/etc/wifi/wpa_supplicant_overlay.conf -N \
    -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
    -I/system/etc/wifi/p2p_supplicant_overlay.conf \
    -O/data/misc/wifi/sockets \
    -puse_p2p_group_interface=1 -e/data/misc/wifi/entropy.bin \
    -g@android:wpa_wlan0
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

#for ssv6051p wifi
service ssv_p2p_supp /system/bin/wpa_supplicant \
    -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
    -I/system/etc/wifi/p2p_supplicant.conf \
    -e/data/misc/wifi/entropy.bin -N \
    -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
    -O/data/misc/wifi/sockets \
    -g@android:wpa_wlan0
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

service hostapd /system/bin/hostapd /data/misc/wifi/hostapd.conf
    class main
    disabled
    oneshot

service wifiservice /system/bin/wifiservice
    class main
    user root
    disabled
    oneshot

service btservice /system/bin/btservice
    class main
    user root
    disabled
    oneshot
